//
//  TZDiscoverTableViewCell.m
//  wangYiLottery
//
//  Created by mac on 16/2/2.
//  Copyright © 2016年 tz. All rights reserved.
//

#import "TZDiscoverTableViewCell.h"
#import "TZDisCoverModel.h"

@interface TZDiscoverTableViewCell ()
@property (nonatomic, strong) UIImageView *iconImage;
@property (nonatomic, strong) UIImageView *titleImage;
@property (nonatomic, strong) UILabel *subTitleLabel;
@end

@implementation TZDiscoverTableViewCell

- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

+ (instancetype)settingCellWithTableview:(UITableView *)tableView {
    static NSString *discoverID = @"discoverID";
    TZDiscoverTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:discoverID];
    if (cell == nil) {
        cell = [[TZDiscoverTableViewCell alloc] init];
    }
    return cell;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.iconImage = [[UIImageView alloc] init];
        [self addSubview:self.iconImage];
        self.titleImage = [[UIImageView alloc] init];
        [self addSubview:self.titleImage];
        self.subTitleLabel = [[UILabel alloc] init];
        [self addSubview:self.subTitleLabel];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self setupUI];
}

//更新UI
- (void)setupUI {
    [self addTitleInCotroller];
    [self addSubTitleInController];
    [self addImageInController];
}

//主标题
- (void)addTitleInCotroller {
//    self.titleImage.image = [UIImage imageNamed:self.model.title];
    [self.titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).offset(8);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(20);
    }];
}

//添加图片
- (void)addImageInController {
//    self.iconImage.image = [UIImage imageNamed:self.model.icon];
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(8);
        make.bottom.equalTo(self).offset(-8);
        make.right.equalTo(self).offset(-8);
        make.height.mas_equalTo(self.iconImage.mas_width);
    }];
}

//添加子标题
- (void)addSubTitleInController {
//    self.subTitleLabel.text = self.model.subTitle;
    [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(8);
        make.bottom.equalTo(self).offset(-8);
        make.height.mas_equalTo(16);
        make.right.equalTo(self.iconImage.mas_left);
    }];
}

- (void)setModel:(TZDisCoverModel *)model {
    _model = model;
    self.iconImage.image = [UIImage imageNamed:model.icon];
    self.titleImage.image = [UIImage imageNamed:model.title];
    self.subTitleLabel.text = model.subTitle;
}
@end
